<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="日期" prop="date">
        <el-date-picker v-model="queryParams.startDate" type="date" placeholder="请选择日期"
                        value-format="yyyy-MM-dd" clearable/>至
        <el-date-picker v-model="queryParams.endDate" type="date" placeholder="请选择日期"
                        value-format="yyyy-MM-dd" clearable/>
<!--        <el-input v-model="queryParams.date" clearable/>-->
      </el-form-item>
      <el-form-item label="渠道" prop="branch">
        <el-select v-model="queryParams.branch" placeholder="请选择渠道" clearable>
          <el-option v-for="dict in dict.type.sys_branch" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="邀请关系" prop="branch">
        <el-select v-model="queryParams.isInvite" placeholder="请选择是否有邀请关系">
          <el-option v-for="dict in isInviteDict" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="渠道" align="center" prop="branch">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_branch" :value="scope.row.branch"/>
        </template>
      </el-table-column>
      <el-table-column label="充值金额" align="center" prop="sumPrice"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  month
} from "@/api/service/statistics/statistics";

export default {
  name: "monthStatistics",
  dicts: ['sys_branch'],
  data() {
    return {
      open: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 封禁IP和设备记录表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startDate: undefined,
        endDate: undefined,
        branch: undefined,
        isInvite: 0
      },
      isInviteDict : [{label: '有',value: 1},{label: '无',value: 0}],
    };
  },
  created() {
    var date = new Date();
    var first = new Date(date.getFullYear(), date.getMonth(), 1);
    var last = new Date(date.getFullYear(), date.getMonth() + 1, 0);
    this.queryParams.startDate = first.getFullYear() + '-' + this.formatNumber(first.getMonth() + 1) + '-' + this.formatNumber(first.getDate());
    this.queryParams.endDate = last.getFullYear() + '-' + this.formatNumber(last.getMonth() + 1) + '-' + this.formatNumber(last.getDate());
    this.getList();
  },
  methods: {
    formatNumber(num){
      return num < 10 ? '0' + num : num;
    },
    /** 查询封禁IP和设备记录列表 */
    getList() {
      this.loading = true;
      month(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd(){
      this.open = true
    }
  }
};
</script>
